﻿#pragma once

#include <chrono>
#include <sys/time.h>

namespace os
{
    using clock_t = std::chrono::system_clock;
    using time_point_t = clock_t::time_point;
    using milliseconds_t = unsigned long long;
    using seconds_t = unsigned long long;
    //using timezone_t = void*;
#ifdef __WIN32
    struct timezone
    {
        int tz_minuteswest;
        int tz_dsttime;
    };
    using timezone_t = timezone;
#else
    using timezone_t = __timezone_ptr_t;
#endif
    using tm_t = tm;

    /**
     * @brief 当前系统时钟的时间点
     */
    time_point_t now_time_point() noexcept;

    /**
     * @brief 转成本地时间
     */
    tm_t localtime(const time_t &time) noexcept;

    /**
     * @brief 当前时间转成本地时间
     */
    tm_t localtime() noexcept;

    /**
     * @brief 日历时间转换为用UTC时间表示的时间
     */
    tm_t gmtime(const time_t &time) noexcept;
    
    /**
     * @brief 当前时间用UTC的时间表示
     */
    tm_t gmtime() noexcept;

    int gettimeofday(timeval *tv, timezone_t* tz = nullptr);

    milliseconds_t get_milliseconds_since_epoch();
    
    seconds_t get_seconds_since_epoch();
} // namespace os

#include "time_inl.h"